package cn.starrysky108.simpleerp.article.controller;


import cn.starrysky108.simpleerp.article.entity.Article;
import cn.starrysky108.simpleerp.article.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章 前端控制器
 * </p>
 *
 * @author Carl Lee
 * @since 2021-08-14
 */
@RestController
@RequestMapping("/articles")
@Api(tags = "测试类接口")
public class ArticleController {
    private final ArticleService articleService;

    @Autowired
    public ArticleController(ArticleService articleService) {
        this.articleService = articleService;
    }

    @GetMapping("/1")
    @ApiOperation("查看文章")
    @PreAuthorize("hasRole('ROLE_root')")
    public Article list1() {
        return articleService.getArticle(1448676942515081217L);
    }

    @GetMapping("/2")
    @ApiOperation("查看文章")
    @PreAuthorize("hasRole('ROLE_admin')")
    public Article list2() {
        return articleService.getArticle(1448676942515081217L);
    }

    @GetMapping("/3")
    @ApiOperation("查看文章")
    @PreAuthorize("hasRole('ROLE_test')")
    public Article list3() {
        return articleService.getArticle(1448676942515081217L);
    }

    @GetMapping("/4/{id}")
    @ApiOperation("查看文章")
    @PreAuthorize("#id=='1'")
    public Article list4(@PathVariable String id) {
        return articleService.getArticle(1448676942515081217L);
    }

}
